# feedback/serializers.py
from rest_framework import serializers
from .models import UserFeedback


class UserFeedbackSerializer(serializers.ModelSerializer):
    class Meta:
        model = UserFeedback
        fields = ['user', 'rating', 'feedback_type', 'content', 'timestamp']
        read_only_fields = ['timestamp']

    # 可选：将用户自动设为当前请求的用户
    def create(self, validated_data):
        validated_data['user'] = self.context['request'].user
        return super().create(validated_data)
